<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2023-10-19 14:36:26
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Models;

use App\Traits\MaterialTrait;
use Illuminate\Support\Facades\App;

class ComprehensiveCarryDetails extends BaseModel
{
    use MaterialTrait;

    public $timestamps = true;
    public $table = "sys_comprehensive_carry_detail";
    protected $guarded = [];



    public function main()
    {
        return $this->belongsTo(ComprehensiveCarry::class, "main_id");
    }
    public function getSourceAttribute()
    {
        return isEmpty($this->source_model) ? null :
            App::make($this->source_model)->where($this->source_key, "=", $this->source_value)->first();
    }
    public function _deleted($model)
    {
        // dd($model->source);
        $model->source?->removeCarryItem();
    }
}
